package client;




import bean.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findUserByManyCondition")
public class FindProductByManyConditionServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//1.获取表单数据
		String id = request.getParameter("id"); // 学生id
		id = new String(id.getBytes("ISO-8859-1"), "UTF-8");
		String name = request.getParameter("name"); // 学生名称
		name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
		String category = request.getParameter("address"); // 地址类别
		category = new String(category.getBytes("ISO-8859-1"), "UTF-8");
		String username = request.getParameter("username"); // 最小价格
		username = new String(username.getBytes("ISO-8859-1"), "UTF-8");
		// 2.创建UserService对象
		UserService service = new UserService();
		// 3.调用service层多条件查询的方法
		List<User> ps = service.findUserByManyCondition(id, name, category,username);
		// 4.将条件查询的结果放进request作用域中
		request.setAttribute("ps", ps);
		// 5.请求转发到学生列表首页list.jsp页面
		request.getRequestDispatcher("/list.jsp").forward(request, response);
	}
}
